package top.kaoshanji.p3ch04a;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import top.kaoshanji.p3ch04a.mapper.PersonMapper;
import top.kaoshanji.p3ch04a.model.Person;
import top.kaoshanji.p3ch04a.util.SqlSessionUtil;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/19 17:50
 */
public class PersonMapperTest {

    /**
     * 代码清单test-p3ch04a-85页a：根据公民id查询公民和身份证信息（resultMap节点）
     */
    @Test
    public void testFindPersonById1() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);

            Person person = personMapper.findPersonById1(1);
            System.out.println(person);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }

    /**
     * 代码清单test-p3ch04a-87页a：根据公民id查询公民和身份证信息（association标签之关联嵌套映射）
     */
    @Test
    public void testFindPersonById2() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);

            Person person = personMapper.findPersonById2(1);
            System.out.println(person);
        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }

    /**
     * 代码清单test-p3ch04a-89页a：根据公民id查询公民和身份证信息（association标签之关联嵌套查询）
     */
    @Test
    public void testFindPersonById3() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);

            Person person = personMapper.findPersonById3(1);
            System.out.println(person);
        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }




}
